#!/bin/sh
#
# webssh -- login the docker lab via web ssh
#
# Copyright (C) 2016-2021 Wu Zhangjin <falcon@ruma.tech>
#

TOP_DIR="$(cd "$(dirname "$0")"/../../ && pwd)"
. "$TOP_DIR"/tools/docker/config >/dev/null

prepare_login || exit 0

show_lab ()
{
  info_print "Please login via ssh client with:"
  echo
  echo "    SSH_IP: $VNC_IP"
  echo "  SSH_PORT: $CONTAINER_SSH_PORT"
  echo "      User: $UNIX_USER"
  echo "  Password: $UNIX_PWD"
  echo "   Workdir: $LAB_WORKDIR/$CURRENT"
  echo

  info_print "Or access via web browser:"
  echo "  $WEBSSH_URL"
  echo

  echo "Note: If running on a remote server, use external ip or domain name instead of 'localhost':"
  echo
  echo "      $ echo \$ip_or_domain_name > '$LAB_HOST'"
  echo "      $ tools/docker/release $LAB_NAME"
  echo
}

log_print "Get cached data"
get_vars VNC_IP UNIX_USER UNIX_PWD
get_host

WEBSSH_URL="$WEB_HTTP://${HOST}:${HOST_WEBSSH_PORT}?ssh=ssh://$UNIX_USER:$UNIX_PWD@$VNC_IP:$CONTAINER_SSH_PORT"

show_lab

browse_url "$WEBSSH_URL"
